<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>配送设置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
	<script src="__STATIC__/admin/js/address3.js?v=1"></script>
	<style>
	.layui-form-label{width:130px!important}
	#ggtable .layui-input{ display:inline;height:30px}
	#ggtable .layui-btn{ margin-top:-3px;margin-left:1px}
	</style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-card layui-col-md12">
				<div class="layui-card-header">
					{if !$info['id']}<i class="fa fa-plus"></i> 添加配送模板{else}<i class="fa fa-pencil"></i> 编辑配送模板{/if}
					<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
				</div>
				<div class="layui-card-body" pad15>
					<div class="layui-form" lay-filter="">
						<input type="hidden" name="info[id]" value="{$info['id']}">
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">配送方式：</label>
							<div class="layui-input-inline" style="width:500px">
								<input type="radio" name="info[pstype]" value="0" title="普通快递" {if !$info['id'] || $info['pstype']==0}checked{/if} lay-filter="pstype">
								<input type="radio" name="info[pstype]" value="1" title="到店自提" {if $info['pstype']==1}checked{/if} lay-filter="pstype">
								<input type="radio" name="info[pstype]" value="2"  title="同城配送" {if $info['pstype']==2}checked{/if} lay-filter="pstype">
								<!-- <input type="radio" name="info[pstype]" value="3" title="自动发货" {if $info['pstype']==3}checked{/if} lay-filter="pstype"> -->
								
								
								
								

							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">显示名称：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[name]" {if $info['pstype']==12 & $info['bid']>0}disabled{/if}  value="{if !$info['id']}普通快递{else}{$info['name']}{/if}" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
							</div>
						</div>

						<div id="pstype0_div" style="{if $info['pstype']!=0 && $info['pstype']!=10}display:none{/if}">
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:100px">计价方式：</label>
								<div class="layui-input-inline">
									<input type="radio" name="info[type]" value="1" title="按重量" {if !$info['id'] || $info['type']==1}checked{/if} lay-filter="ftype">
									<input type="radio" name="info[type]" value="2" title="按件数" {if $info['type']==2}checked{/if} lay-filter="ftype">
								</div>
							</div>
							<div class="layui-form-item" id="setgg">
								<label class="layui-form-label" style="width:100px">区域及价格：</label>
								<div class="layui-input-inline" style="width:auto">
									<table id="ggnamediv"  class="layui-table" style="width:900px">
										<thead>
										<tr id="ggtitle1" {if $info['type']==2}style="display:none"{/if}>
											<th style="width:300px">区域</th>
											<th style="width:90px">是否配送</th>
											<th>首重重量(克)</th>
											<th>首重费用(元)</th>
											<th>续重重量(克)</th>
											<th>续重费用(元)</th>
											<th>操作</th>
										</tr>
										<tr id="ggtitle2" {if !$info['id'] || $info['type']==1}style="display:none"{/if}>
											<th style="width:300px">区域</th>
											<th style="width:90px">是否配送</th>
											<th>首件件数(个)</th>
											<th>首件费用(元)</th>
											<th>续件件数(个)</th>
											<th>续件费用(元)</th>
											<th>操作</th>
										</tr>
										</thead>
										{php} $pricedata = json_decode($info['pricedata'],true);{/php}
										{if $pricedata}
										{foreach $pricedata as $k=>$gg}
										<tr>
											<td class="areasettd">
												<span class="cityshtml">{$gg.region}</span>
												<input type="hidden" class="citys" name="citys[]" value="{$gg.region}" />
												{if $k!=0}<button class="layui-btn layui-btn-sm layui-btn-primary" onclick="editArea(this)"><i class="fa fa-edit"></i> 编辑</button>{/if}
											</td>
											{if $k==0}
											<td><input type="hidden" name="ispeisong[]" value="1"/></td>
											{else}
											<td><input type="checkbox" name="ispeisong[]" value="1" lay-skin="switch" lay-text="开启|关闭" {$gg['ispeisong']==2?'':'checked'}/></td>
											{/if}
											<td><input type="text" class="layui-input" name="fristweight[]" value="{$gg.fristweight}" style="width:80px"/></td>
											<td><input type="text" class="layui-input" name="fristprice[]" value="{$gg.fristprice}" style="width:80px"/></td>
											<td><input type="text" class="layui-input" name="secondweight[]" value="{$gg.secondweight}" style="width:80px"/></td>
											<td><input type="text" class="layui-input" name="secondprice[]" value="{$gg.secondprice}" style="width:80px"/></td>
											{if $k==0}
											<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggtype()">添加</button></td>
											{else}
											<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>
											{/if}
										</tr>
										{/foreach}
										{else}
										<tr>
											<td><span class="cityshtml">全国(默认运费)</span><input type="hidden" class="citys" name="citys[]" value="全国(默认运费)" /></td>
											<td><input type="hidden" name="ispeisong[]" value="1"/></td>
											<td><input type="text" class="layui-input" name="fristweight[]" value="1000" style="width:80px"/></td>
											<td><input type="text" class="layui-input" name="fristprice[]" value="0" style="width:80px"/></td>
											<td><input type="text" class="layui-input" name="secondweight[]" value="1000" style="width:80px"/></td>
											<td><input type="text" class="layui-input" name="secondprice[]" value="0" style="width:80px"/></td>
											<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggtype()">添加</button></td>
										</tr>
										{/if}
									</table>
									<div class="layui-word-aux" id="ggaux1" {if $info['type']==2}style="display:none"{/if}>根据重量来计算运费，当物品不足《首重重量》时，按照《首重费用》计算，超过部分按照《续重重量》和《续重费用》乘积来计算，首重续重为空时默认按照1000计算</div>
									<div class="layui-word-aux" id="ggaux2" {if !$info['id'] || $info['type']==1}style="display:none"{/if}>根据件数来计算运费，当物品不足《首件件数》时，按照《首件费用》计算，超过部分按照《续件件数》和《续件费用》乘积来计算</div>
								</div>
							</div>
						</div>

						<div id="pstype1_div" style="{if $info['pstype']!=1}display:none{/if}">
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:100px">自提门店：</label>
								<div class="layui-input-inline">
									<input type="radio"   name="info[storetype]" value="0" title="全部" {if !$info['storetype'] || $info['storetype']==0}checked{/if} lay-filter="storetype">
									<input type="radio"   name="info[storetype]" value="1" title="选择门店" {if $info['storetype']==1}checked{/if} lay-filter="storetype">
								</div>
							</div>
							<div class="layui-form-item" id="storetype1_div" {if !$info['storetype'] || $info['storetype']==0}style="display:none"{/if}>
								<label class="layui-form-label" style="width:100px">选择门店：</label>
								<div class="layui-input-inline" style="width:500px">
								{php} $storeids = explode(',',$info['storeids']);{/php}
								{foreach $mendianArr as $k=>$v}
									<input type="checkbox" name="info[storeid][]" value="{$k}" title="{$v}" lay-skin="primary" {if in_array($k,$storeids)}checked{/if}  >
								{/foreach}
								</div>
							</div>
							
						</div>

						<div id="pstype2_div" style="{if !in_array($info['pstype'],[2,12])}display:none{/if}">
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:100px">配送费：</label>
								<div class="layui-input-inline" style="width: 100px;">
									<input style="border-radius:0 2px 2px 0" {if $info['pstype']==12 & $info['bid']>0}disabled{/if}  type="text" name="info[peisong_juli1]" class="layui-input" value="{$info.peisong_juli1}">
								</div>
								<div class="layui-form-mid">公里内</div>
								<div class="layui-input-inline" style="width: 100px;">
									<input style="border-radius:0 2px 2px 0" {if $info['pstype']==12 & $info['bid']>0}disabled{/if}  type="text" name="info[peisong_fee1]" class="layui-input" value="{$info.peisong_fee1}">
								</div>
								<div class="layui-form-mid">元；每超出</div>
								<div class="layui-input-inline" style="width: 100px;">
									<input style="border-radius:0 2px 2px 0" {if $info['pstype']==12 & $info['bid']>0}disabled{/if}  type="text" name="info[peisong_juli2]" class="layui-input" value="{$info.peisong_juli2}">
								</div>
								<div class="layui-form-mid">公里，加</div>
								<div class="layui-input-inline" style="width: 100px;">
									<input style="border-radius:0 2px 2px 0" {if $info['pstype']==12 & $info['bid']>0}disabled{/if}  type="text" name="info[peisong_fee2]" class="layui-input" value="{$info.peisong_fee2}">
								</div>
								<div class="layui-form-mid">元</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:100px">配送范围：</label>
								<div class="layui-input-block" style="width:300px">
									<input type="radio" name="info[peisong_rangetype]"  {if $info['pstype']==12 & $info['bid']>0}disabled{/if} value="0" title="圆形范围" {if !$info['id'] || $info['peisong_rangetype']==0}checked{/if} lay-filter="rangetypeset">
									<input type="radio" name="info[peisong_rangetype]" {if $info['pstype']==12 & $info['bid']>0}disabled{/if}  value="1" title="多边形范围" {if $info['id'] && $info['peisong_rangetype']==1}checked{/if} lay-filter="rangetypeset">
								</div>
								<div class="form-group" style="margin-left:130px;padding-top:10px;padding-bottom:5px">
									<script src="https://webapi.amap.com/maps?v=1.4.0&key=cc6545949691fe61692f4036ab2f0336&plugin=AMap.PolyEditor,AMap.CircleEditor"></script>
									<div id="container" class="map" style="width:800px;height: 600px;"></div>
								</div>
								<div id="rangetypeset0" style="{if $info['id'] && $info['peisong_rangetype']==1}display:none{/if}">
									<div class="layui-form-mid" style="margin-left:130px;">中心点坐标</div>
									<div class="layui-input-inline" style="width: 100px;">
										<input type="text" name="info[peisong_lng]"  {if $info['pstype']==12 & $info['bid']>0}disabled{/if} class="layui-input" value="{$info.peisong_lng}">
									</div>
									<div class="layui-form-mid">,</div>
									<div class="layui-input-inline" style="width: 100px;">
										<input type="text" name="info[peisong_lat]"  {if $info['pstype']==12 & $info['bid']>0}disabled{/if} class="layui-input" value="{$info.peisong_lat}">
									</div>
									<div class="layui-form-mid">配送半径</div>
									<div class="layui-input-inline" style="width: 100px;">
										<input type="text" name="info[peisong_range]" {if $info['pstype']==12 & $info['bid']>0}disabled{/if}  class="layui-input" value="{$info.peisong_range}">
									</div>
									<div class="layui-form-mid">米</div>
								</div>
								<div id="rangetypeset1" style="{if !$info['id'] || $info['peisong_rangetype']==0}display:none{/if}">
									<input type="hidden" name="info[peisong_rangepath]" class="layui-input" value="{$info.peisong_rangepath}">
									<div class="layui-form-mid" style="margin-left:130px;">注：多边形的形状尽量简洁，不要有交叉线</div>

									
									<div class="layui-form-item">
										<label class="layui-form-label" style="width:130px">配送点：</label>
										<div class="layui-input-inline" style="width:150px">
											<input type="text" name="info[peisong_lng2]" value="{$info['peisong_lng2']}" class="layui-input">
										</div>
										<div class="layui-form-mid">-</div>
										<div class="layui-input-inline" style="width:150px">
											<input type="text" name="info[peisong_lat2]" value="{$info['peisong_lat2']}" class="layui-input">
										</div>
										<button class="layui-btn layui-btn-primary" onclick="choosezuobiao()" style="float:left">选择坐标</button>
									</div>

								</div>
							</div>
						</div>

						<div id="pstype5_div" style="{if $info['pstype']!=5}display:none{/if}">
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:100px">配送门店：</label>
								<div class="layui-input-inline">
									<input type="radio" name="storetype5" value="0" title="全部" {if !$info['storetype'] || $info['storetype']==0}checked{/if} lay-filter="storetype5">
									<input type="radio" name="storetype5" value="1" title="选择门店" {if $info['storetype']==1}checked{/if} lay-filter="storetype5">
								</div>
							</div>
							<div class="layui-form-item" id="storetype5_div" {if !$info['storetype'] || $info['storetype']==0}style="display:none"{/if}>
								<label class="layui-form-label" style="width:100px">选择门店：</label>
								<div class="layui-input-inline" style="width:500px">
									{php} $storeids = explode(',',$info['storeids']);{/php}
									{foreach $mendianArr as $k=>$v}
									<input type="checkbox" name="storeid5[]" value="{$k}" title="{$v}" lay-skin="primary" {if in_array($k,$storeids)}checked{/if}>
									{/foreach}
								</div>
							</div>
						</div>

						<div id="pstype11_div" style="{if $info['pstype']!=11}display:none{/if}">
							<div class="layui-form-item" id="setgg11">
								<label class="layui-form-label" style="width:100px">物流公司：</label>
								<div class="layui-input-inline" style="width:auto">
									<table id="ggname11div"  class="layui-table" style="width:900px">
										<thead>
										<tr>
											<th>名称</th>
											<th>地区</th>
											<th>收货地址/电话</th>
											<th>发货地址/电话</th>
											<th>价格(元)</th>
											<th>操作</th>
										</tr>
										</thead>
										{php} $pricedata = json_decode($info['type11pricedata'],true); if(!$pricedata) $pricedata= [[]];{/php}
										{foreach $pricedata as $k=>$gg}
										<tr>
											<td>{$gg.name}</td>
											<td>{$gg.province}{$gg.city}{$gg.area}</td>
											<td>{$gg.receive_address}<br>{$gg.receive_tel}</td>
											<td>{$gg.send_address}<br>{$gg.send_tel}</td>
											<td>{$gg.price}</td>
											<td>
											<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="editggtype11(this)">编辑</button>
											{if $k==0}<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggtype11()">添加</button>
											{else}
											<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button>
											{/if}
											<textarea name="type11pricedata[]" style="display:none">{:json_encode($gg)}</textarea>
											</td>
										</tr>
										{/foreach}
									</table>
								</div>
							</div>
							<script>
								function editggtype11(obj){
									var thispricedata = $(obj).parent().find("textarea[name='type11pricedata[]']").val();
									if(thispricedata){
										thispricedata = JSON.parse(thispricedata);
									}else{
										thispricedata = {};
									}
									var html = '<div style="margin:20px auto;">';
									html+='<div class="layui-form" lay-filter="">';
									html+='	<div class="layui-form-item">';
									html+='		<label class="layui-form-label" style="width:100px">物流名称：</label>';
									html+='		<div class="layui-input-inline" style="width:200px">';
									html+='			<input type="text" name="type11_name" value="'+(thispricedata.name||'')+'" class="layui-input">';
									html+='		</div>';
									html+='	</div>';
									html+='	<div class="layui-form-item">';
									html+='		<label class="layui-form-label" style="width:100px">地区：</label>';
									html+='		<div class="layui-input-inline">';
									html+='			<div class="layui-input-inline">';
									html+='				<select name="type11_province" id="type11_province" lay-filter="type11_province"></select>';
									html+='			</div>';
									html+='			<div class="layui-input-inline">';
									html+='				<select name="type11_city" id="type11_city" lay-filter="type11_city"></select>';
									html+='			</div>';
									html+='			<div class="layui-input-inline">';
									html+='				<select name="type11_area" id="type11_area" ></select>';
									html+='			</div>';
									html+='		</div>';
									html+='	</div>';
									html+='	<div class="layui-form-item">';
									html+='		<label class="layui-form-label" style="width:100px">收货地址：</label>';
									html+='		<div class="layui-input-inline" style="width:200px">';
									html+='			<input type="text" name="type11_receive_address" value="'+(thispricedata.receive_address||'')+'" class="layui-input">';
									html+='		</div>';
									html+='	</div>';
									html+='	<div class="layui-form-item">';
									html+='		<label class="layui-form-label" style="width:100px">收货电话：</label>';
									html+='		<div class="layui-input-inline" style="width:200px">';
									html+='			<input type="text" name="type11_receive_tel" value="'+(thispricedata.receive_tel||'')+'" class="layui-input">';
									html+='		</div>';
									html+='	</div>';
									html+='	<div class="layui-form-item">';
									html+='		<label class="layui-form-label" style="width:100px">发货地址：</label>';
									html+='		<div class="layui-input-inline" style="width:200px">';
									html+='			<input type="text" name="type11_send_address" value="'+(thispricedata.send_address||'')+'" class="layui-input">';
									html+='		</div>';
									html+='	</div>';
									html+='	<div class="layui-form-item">';
									html+='		<label class="layui-form-label" style="width:100px">发货电话：</label>';
									html+='		<div class="layui-input-inline" style="width:200px">';
									html+='			<input type="text" name="type11_send_tel" value="'+(thispricedata.send_tel||'')+'" class="layui-input">';
									html+='		</div>';
									html+='	</div>';
									html+='	<div class="layui-form-item">';
									html+='		<label class="layui-form-label" style="width:100px">价格：</label>';
									html+='		<div class="layui-input-inline" style="width:200px">';
									html+='			<input type="text" name="type11_price" value="'+(thispricedata.price||'')+'" class="layui-input">';
									html+='		</div>';
									html+='	</div>';
									html+='	<div class="layui-form-item">';
									html+='		<label class="layui-form-label" style="width:100px"></label>';
									html+='		<div class="layui-input-inline">';
									html+='			<button class="layui-btn layui-btn-normal" lay-submit lay-filter="type11_submit">确 定</button>';
									html+='		</div>';
									html+='	</div>';
									html+='</div>';
									html+='</div>'
									var type11editlayer = layer.open({type:1,area:['600px','600px'],content:html,title:'填写物流信息',shadeClose:true});
									layui.form.render();
									address3('type11_province','type11_city','type11_area',thispricedata.province,thispricedata.city,thispricedata.area);
									layui.form.on('submit(type11_submit)', function(obj2){
										var field = obj2.field;
										console.log(field);
										var thispricedata = {};
										thispricedata.name = field.type11_name
										thispricedata.province = field.type11_province
										thispricedata.city = field.type11_city
										thispricedata.area = field.type11_area
										thispricedata.receive_address = field.type11_receive_address
										thispricedata.receive_tel = field.type11_receive_tel
										thispricedata.send_address = field.type11_send_address
										thispricedata.send_tel = field.type11_send_tel
										thispricedata.price = field.type11_price
										$(obj).parent().find("textarea[name='type11pricedata[]']").val(JSON.stringify(thispricedata));
										$(obj).parent().parent().find('td').eq(0).html(thispricedata.name);
										$(obj).parent().parent().find('td').eq(1).html(thispricedata.province+thispricedata.city+thispricedata.area);
										$(obj).parent().parent().find('td').eq(2).html(thispricedata.receive_address+'<br>'+thispricedata.receive_tel);
										$(obj).parent().parent().find('td').eq(3).html(thispricedata.send_address+'<br>'+thispricedata.send_tel);
										$(obj).parent().parent().find('td').eq(4).html(thispricedata.price);
										layer.close(type11editlayer);
									});
								}
								function addggtype11(){
									var gghtml = '<tr>';
									gghtml += '<td></td>';
									gghtml += '<td></td>';
									gghtml += '<td></td>';
									gghtml += '<td></td>';
									gghtml += '<td></td>';
									gghtml += '<td>';
									gghtml += '	<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="editggtype11(this)">编辑</button>';
									gghtml += '	<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button>';
									gghtml += '	<textarea name="type11pricedata[]" style="display:none"></textarea>';
									gghtml += '</td>';
									gghtml += '</tr>';
									console.log(gghtml)
									$('#ggname11div').append(gghtml);
								}
							</script>
						</div>

						<div class="layui-form-item" id="pstype02_div" style="{if $info['pstype']==1 ||  $info['pstype']==3}display:none{/if}">
							<label class="layui-form-label" style="width:100px">满额包邮：</label>
							<div class="layui-input-inline" style="width:70px">
								<input type="checkbox" name="info[freeset]" value="1"    lay-text="开启|关闭" lay-skin="switch" lay-filter="freeset" {if $info['freeset']==1}checked{/if}>
							</div>
							<div style="float:left;{if !$info['id'] || $info['freeset']==0}display:none{/if}" id="freesetdiv">
								<div class="layui-form-mid">满</div>
								<div class="layui-input-inline" style="width:70px"><input type="text" name="info[free_price]" value="{$info.free_price}"   class="layui-input"></div>
								<div class="layui-form-mid">元包邮</div>
							</div>
						</div>
						<div class="layui-form-item" id="pstype12_div" style="{if $info['pstype']==1 ||  $info['pstype']==3}display:none{/if}">
							<label class="layui-form-label" style="width:100px">满额起送：</label>
							<div class="layui-input-inline" style="width:70px">
								<input type="checkbox" name="info[minpriceset]" value="1"   lay-text="开启|关闭" lay-skin="switch" lay-filter="minpriceset" {if $info['minpriceset']==1}checked{/if}>
							</div>
							<div style="float:left;{if !$info['id'] || $info['minpriceset']==0}display:none{/if}" id="minpricesetdiv">
								<div class="layui-form-mid">满</div>
								<div class="layui-input-inline" style="width:70px"><input type="text" name="info[minprice]" value="{$info.minprice}" class="layui-input"  ></div>
								<div class="layui-form-mid">元起送</div>
							</div>
						</div>

						<div id="pstype3_div" style="{if $info['pstype']!=3}display:none{/if}">
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:100px">发货信息：</label>
								<div class="layui-input-inline" style="width:300px">
									<input type="radio" name="info[pscontenttype]" value="0" title="固定信息" {if !$info['id'] || $info['pscontenttype']==0}checked{/if} lay-filter="pscontenttype">
									<input type="radio" name="info[pscontenttype]" value="1" title="不固定信息(在线卡密)" {if $info['pscontenttype']==1}checked{/if} lay-filter="pscontenttype">
								</div>
								<div class="layui-form-mid"><span style="color:red">选择自动发货请务必在需要自动发货的商品中选择该运费模板，否则不显示</span></div>
							</div>
							<div class="layui-form-item" style="{if $info['pscontenttype']!=0}display:none{/if}" id="pscontent0">
								<label class="layui-form-label" style="width:100px"></label>
								<div class="layui-input-inline" style="width:500px">
									<textarea type="text" name="info[pscontent]" placeholder="请输入发货信息" class="layui-textarea">{$info.pscontent}</textarea>
								</div>
							</div>
							<div class="layui-form-item" style="{if $info['pscontenttype']!=0}display:none{/if}" id="pscontent1">
								<label class="layui-form-label" style="width:100px"></label>
								<div class="layui-form-mid">请稍后在配送列表中上传卡密信息；用户购买几件将发送几个卡密信息</div>
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px" id="pstimename">{if $info['pstype']==1}提货{else}配送{/if}时间：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[pstimeset]" value="0"   title="关闭" {if !$info['pstimeset'] || $info['pstimeset']==0}checked{/if} lay-filter="pstimeset">
								<input type="radio" name="info[pstimeset]" value="1"   title="开启" {if $info['pstimeset']==1}checked{/if} lay-filter="pstimeset">
							</div>
							<div class="layui-form-mid layui-word-aux">开启后用户下单时可以选择配送时间或提货时间</div>
						</div>

						<div id="pstimeset_div" {if !$info['pstimeset'] || $info['pstimeset']==0}style="display:none"{/if}>
							<div id="pstimedata">
							{php} $pstimedata = json_decode($info['pstimedata'],true);{/php}
							{if !$pstimedata}{php}$pstimedata = [['day'=>1,'hour'=>0,'minute'=>0,'hour2'=>0,'minute2'=>0]];{/php}{/if}
							{foreach $pstimedata as $k=>$v}
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:100px">{if $k==0}可选时间：{/if}</label>
								<div class="layui-input-inline" style="width:120px">
									<select name="pstimeday[]"  >
										<option value="1" {if $v['day']==1}selected{/if}>当天</option>
										{for start="2" end="16"}
										<option value="{$i}" {if $v['day']==$i}selected{/if}>第{$i}天</option>
										{/for}
									</select>
								</div>
								<div class="layui-input-inline" style="width:90px">
									<select name="pstimehour[]"  >
										{for start="0" end="24"}
										<option value="{$i}" {if $v['hour']==$i}selected{/if}>{$i}</option>
										{/for}
									</select>
								</div>
								<div class="layui-form-mid">点</div>
								<div class="layui-input-inline" style="width:90px">
									<select name="pstimeminute[]"  >
										{for start="0" end="60"}
										<option value="{$i}" {if $v['minute']==$i}selected{/if}>{$i}</option>
										{/for}
									</select>
								</div>
								<div class="layui-form-mid">分</div>
								<div class="layui-form-mid"> 到 </div>
								
								<div class="layui-input-inline" style="width:90px">
									<select name="pstimehour2[]"  >
										{for start="0" end="24"}
										<option value="{$i}" {if $v['hour2']==$i}selected{/if}>{$i}</option>
										{/for}
									</select>
								</div>
								<div class="layui-form-mid">点</div>
								<div class="layui-input-inline" style="width:90px">
									<select name="pstimeminute2[]"  >
										{for start="0" end="60"}
										<option value="{$i}" {if $v['minute2']==$i}selected{/if}>{$i}</option>
										{/for}
									</select>
								</div>
								<div class="layui-form-mid">分</div>
								{if $k==0}
								<button class="layui-btn layui-btn-primary" onclick="addpstime()"><i class="fa fa-plus"></i></button>
								{else}
								<button class="layui-btn layui-btn-primary" onclick="removepstime(this)"><i class="fa fa-minus"></i></button>
								{/if}
							</div>
							{/foreach}
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:100px">可选条件：</label>
								<div class="layui-form-mid">下单时间早于可选时间</div>
								<div class="layui-input-inline" style="width:70px">
									<input type="text" name="info[psprehour]"   value="{if !$info['id']}4{else}{$info['psprehour']}{/if}" class="layui-input">
								</div>
								<div class="layui-form-mid">小时以上</div>
							</div>
						</div>
						<script>
						function addpstime(){
							var html = '';
							html+='<div class="layui-form-item">';
							html+='	<label class="layui-form-label" style="width:100px"></label>';
							html+='	<div class="layui-input-inline" style="width:120px">';
							html+='		<select name="pstimeday[]">';
							html+='			<option value="1">当天</option>';
							{for start="2" end="16"}
							html+='			<option value="{$i}">第{$i}天</option>';
							{/for}
							html+='		</select>';
							html+='	</div>';
							html+='	<div class="layui-input-inline" style="width:90px">';
							html+='		<select name="pstimehour[]">';
							{for start="0" end="24"}
							html+='			<option value="{$i}">{$i}</option>';
							{/for}
							html+='		</select>';
							html+='	</div>';
							html+='	<div class="layui-form-mid">点</div>';
							html+='	<div class="layui-input-inline" style="width:90px">';
							html+='		<select name="pstimeminute[]">';
							{for start="0" end="60"}
							html+='			<option value="{$i}">{$i}</option>';
							{/for}
							html+='		</select>';
							html+='	</div>';
							html+='	<div class="layui-form-mid">分</div>';
							html+='	<div class="layui-form-mid"> 到 </div>';
							html+='	<div class="layui-input-inline" style="width:90px">';
							html+='		<select name="pstimehour2[]">';
							{for start="0" end="24"}
							html+='			<option value="{$i}">{$i}</option>';
							{/for}
							html+='		</select>';
							html+='	</div>';
							html+='	<div class="layui-form-mid">点</div>';
							html+='	<div class="layui-input-inline" style="width:90px">';
							html+='		<select name="pstimeminute2[]">';
							{for start="0" end="60"}
							html+='			<option value="{$i}">{$i}</option>';
							{/for}
							html+='		</select>';
							html+='	</div>';
							html+='	<div class="layui-form-mid">分</div>';
							html+='	<button class="layui-btn layui-btn-primary" onclick="removepstime(this)"><i class="fa fa-minus"></i></button>';
							html+='</div>';
							$('#pstimedata').append(html);
							layui.form.render();
						}
						function removepstime(obj){
							$(obj).parent().remove();
						}
						</script>
						
						<div class="layui-form-item" id="needlinkinfodiv" style="{if $info['pstype']==0  || $info['pstype']==10 || $info['pstype']==2  || $info['pstype']==11}display:none{/if}">
							<label class="layui-form-label" style="width:100px">联系方式：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[needlinkinfo]"   value="1" title="必填" {if !$info['id'] || $info['needlinkinfo']==1}checked{/if}>
								<input type="radio" name="info[needlinkinfo]"   value="0" title="选填" {if $info['id'] && $info['needlinkinfo']==0}checked{/if}>
							</div>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">提交订单时，联系人和联系电话是否必填</div>
						</div>
						<div class="layui-form-item" id="fwprice_div" style="{if $info['pstype']!=1}display:none{/if}">
							<label class="layui-form-label" style="width:100px">服务费：</label>
							<div class="layui-input-inline" style="width:100px">
								<input type="text" name="info[fwprice]" value="{$info.fwprice|default=0}" class="layui-input">
							</div>
							<div class="layui-form-mid">元</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label">设置表单：</label>
							<div class="layui-input-inline" style="width:800px !important">
								<div class="layui-form-item">
									<!-- <label class="layui-form-label" style="width:100px">添加表单项：</label> -->
									<div class="layui-input-inline" style="width:auto;margin-top:5px">
										<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"   onclick="addelement('input','','',1)"><i class="icon-plus"></i>单行输入</button>
										<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"  onclick="addelement('textarea','','',1)"><i class="icon-plus"></i>多行输入</button>
										<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"  onclick="addelement('radio','','',1)"><i class="icon-plus"></i>单项选择</button>
										<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"  onclick="addelement('checkbox','','',1)"><i class="icon-plus"></i>多项选择</button>
										<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"  onclick="addelement('selector','','',1)"><i class="icon-plus"></i>普通选择</button>
										<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"  onclick="addelement('time','','',1)"><i class="icon-plus"></i>时间选择</button>
										<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"  onclick="addelement('date','','',1)"><i class="icon-plus"></i>日期选择</button>
										<button type="button" class="layui-btn layui-btn-primary layui-btn-sm"  onclick="addelement('upload','','',1)"><i class="icon-plus"></i>上传图片</button>
									</div>
								</div>
								<table class="layui-table" style="width:860px" id="ggtable">
									<thead>
									<tr>
										<th style="width:100px">字段类型</th>
										<th style="width:150px">字段名称</th>
										<th style="width:280px">字段内容</th>
										<th style="width:150px">是否必填</th>
										<th style="width:170px">操作</th>
									</tr>
									</thead>
									<tbody id="datatable">
										
									</tbody>
								</table>
							</div>
						</div>


						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">序号：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[sort]"   value="{$info.sort|default=0}" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">用于排序,越大越靠前</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">状态：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[status]"   value="1" title="开启" {if !$info['id'] || $info['status']==1}checked{/if}>
								<input type="radio" name="info[status]"   value="0" title="关闭" {if $info['id'] && $info['status']==0}checked{/if}>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block" style="margin-left:160px;">
								<button class="layui-btn"   lay-submit lay-filter="formsubmit">提 交</button>
							</div>
						</div>
					</div>
					
				</div>
			</div>
		</div>
  </div>
	<style type='text/css'>
	.modal-areas .layui-layer-content{ position:static;overflow:visible;height:300px}
	.province { float:left; position:relative;width:210px; height:35px; line-height:35px;border:1px solid #fff;}
	.province:hover { border:1px solid #f7e4a5;border-bottom:1px solid #fffec6; background:#fffec6;}
	.province .cityall { margin-top:10px;}
	.province ul { list-style: outside none none;position:absolute;padding:0;background:#fffec6;border:1px solid #f7e4a5;display:none;width:auto; width:300px; z-index:999999;left:-1px;top:32px;}
	.province ul li  { float:left;min-width:60px;margin-left:20px; height:30px;line-height:30px; }
	</style>
	<div id="modal-areas" style="display:none">
	</div> 
	{include file="public/js"/}
	<script>
	layui.form.on('radio(storetype)',function(data){
		if(data.value == '0'){
			$('#storetype1_div').hide();
		}else{
			$('#storetype1_div').show();
		}
	})
	layui.form.on('radio(storetype5)',function(data){
		if(data.value == '0'){
			$('#storetype5_div').hide();
		}else{
			$('#storetype5_div').show();
		}
	})
	layui.form.on('radio(pstype)', function(data){
		$("input[name='info[name]']").removeAttr("disabled");
		if(data.value == '0' || data.value == '10'){
			$('#pstype0_div').show();
			$('#pstype1_div').hide();
			$('#pstype2_div').hide();
			$('#pstype02_div').show();
			$('#pstype12_div').show();
			$('#pstype3_div').hide();
			$('#needlinkinfodiv').hide();
			$('#fwprice_div').hide();
			$("input[name='info[name]']").val('普通快递')
			$('#pstimename').html('配送时间：');
			$('#pstype11_div').hide();
		}else if(data.value == '1'){
			$('#pstype0_div').hide();
			$('#pstype1_div').show();
			$('#pstype2_div').hide();
			$('#pstype02_div').hide();
			$('#pstype12_div').hide();
			$('#pstype3_div').hide();
			$('#pstype5_div').hide();
			$('#needlinkinfodiv').show();
			$('#fwprice_div').show();
			$("input[name='info[name]']").val('到店自提')
			$('#pstimename').html('提货时间：');
			$('#pstype11_div').hide();
		}else if(data.value == '2'){
			$('#pstype0_div').hide();
			$('#pstype1_div').hide();
			$('#pstype2_div').show();
			$('#pstype02_div').show();
			$('#pstype12_div').show();
			$('#pstype3_div').hide();
			$('#pstype5_div').hide();
			$('#needlinkinfodiv').hide();
			$('#fwprice_div').hide();
			$("input[name='info[name]']").val('同城配送');
			$('#pstimename').html('配送时间：');
			$('#pstype11_div').hide();
		}else if(data.value == '3') {
			$('#pstype0_div').hide();
			$('#pstype1_div').hide();
			$('#pstype2_div').hide();
			$('#pstype02_div').hide();
			$('#pstype12_div').hide();
			$('#pstype3_div').show();
			$('#pstype5_div').hide();
			$('#needlinkinfodiv').show();
			$('#fwprice_div').hide();
			$("input[name='info[name]']").val('自动发货');
			$('#pstimename').html('配送时间：');
			$('#pstype11_div').hide();
		}else if(data.value == '5'){
			$('#pstype0_div').hide();
			$('#pstype1_div').hide();
			$('#pstype2_div').hide();
			$('#pstype02_div').show();

			$('#pstype5_div').show();
			$('#pstype12_div').show();
			$('#pstype3_div').hide();
			$('#needlinkinfodiv').hide();
			$('#fwprice_div').hide();
			$("input[name='info[name]']").val('门店配送');
			$('#pstimename').html('配送时间：');
			$('#pstype11_div').hide();
		}else if(data.value == '11'){
			$('#pstype0_div').hide();
			$('#pstype1_div').hide();
			$('#pstype2_div').hide();
			$('#pstype02_div').show();
			$('#pstype12_div').show();
			$('#pstype3_div').hide();
			$('#pstype5_div').hide();
			$('#needlinkinfodiv').hide();
			$('#fwprice_div').hide();
			$('#pstype11_div').show();
		}else if(data.value == '12'){
			$('#pstype0_div').hide();
			$('#pstype1_div').hide();
			$('#pstype2_div').show();
			$('#pstype02_div').show();
			$('#pstype12_div').show();
			$('#pstype3_div').hide();
			$('#pstype5_div').hide();
			$('#needlinkinfodiv').hide();
			$('#fwprice_div').hide();
			$("input[name='info[name]']").val('平台跑腿订单');
			$('#pstimename').html('配送时间：');
			$('#pstype11_div').hide();

			//hh获取总帐号的设置，禁止编辑
			{if $bid>0}
			$.post("{:url('getPtset')}",function(data){
				var data = data.data
				$("input[name='info[name]']").val(data.name);
				$("input[name='info[name]']").attr("disabled","disabled");
				$("input[name='info[peisong_juli1]']").val(data.peisong_juli1);
				$("input[name='info[peisong_juli1]']").attr("disabled","disabled");
				$("input[name='info[peisong_fee1]']").val(data.peisong_fee1);
				$("input[name='info[peisong_fee1]']").attr("disabled","disabled");
				$("input[name='info[peisong_juli2]']").val(data.peisong_juli2);
				$("input[name='info[peisong_juli2]']").attr("disabled","disabled");
				$("input[name='info[peisong_fee2]']").val(data.peisong_fee2);
				$("input[name='info[peisong_fee2]']").attr("disabled","disabled");
				$("input[name='info[peisong_rangetype]']").val(data.peisong_rangetype);
				$("input[name='info[peisong_rangetype]']").attr("disabled","disabled");
				$("input[name='info[peisong_lng]']").val(data.peisong_lng);
				$("input[name='info[peisong_lng]']").attr("disabled","disabled");
				$("input[name='info[peisong_lat]']").val(data.peisong_lat);
				$("input[name='info[peisong_lat]']").attr("disabled","disabled");
				$("input[name='info[peisong_range]']").val(data.peisong_range);
				$("input[name='info[peisong_range]']").attr("disabled","disabled");
			})
			{/if}
		}
	});
	layui.form.on('radio(ftype)', function(data){
		if(data.value == '1'){
			$('#ggtitle1').show();
			$('#ggtitle2').hide();
			$('#ggaux1').show();
			$('#ggaux2').hide();
		}else{
			$('#ggtitle1').hide();
			$('#ggtitle2').show();
			$('#ggaux1').hide();
			$('#ggaux2').show();
		}
	});
	layui.form.on('switch(freeset)',function(data){
		if(data.elem.checked){
			$('#freesetdiv').show();
		}else{
			$('#freesetdiv').hide();
		}
	})
	layui.form.on('switch(minpriceset)',function(data){
		if(data.elem.checked){
			$('#minpricesetdiv').show();
		}else{
			$('#minpricesetdiv').hide();
		}
	})
	layui.form.on('radio(pstimeset)',function(data){
		if(data.value == '0'){
			$('#pstimeset_div').hide();
		}else{
			$('#pstimeset_div').show();
		}
	})
	layui.form.on('radio(pscontenttype)',function(data){
		if(data.value == '0'){
			$('#pscontent0').show();
			$('#pscontent1').hide();
		}else{
			$('#pscontent0').hide();
			$('#pscontent1').show();
		}
	})
	
	$(function(){
		var regiondata = '';
		for(var i in provinceList){
			if(i>0){
				var province = provinceList[i];
				regiondata+='<div class="province">';
				regiondata+='			<label class="checkbox-inline" style="margin-left:20px;">';
				regiondata+='				<input type="checkbox" class="cityall" province="'+province.name+'"/> '+province.name;
				regiondata+='				<span class="citycount" style="color:#ff6600"></span>';
				regiondata+='			</label>';
				if(province.cityList){
					regiondata+='		<ul>';
					for(var j in province.cityList){
						var city = province.cityList[j];
						regiondata+='		<li>';
						regiondata+='			<label class="checkbox-inline">';
						regiondata+='				<input type="checkbox" class="city" style="margin-top:8px;" city="'+city.name+'" /> '+city.name;
						regiondata+='			</label>';
						regiondata+='		</li>';
					}
					regiondata+='		</ul>';
				}
				regiondata+='		</div>';
			}
		}
		$('#modal-areas').html(regiondata);
		$('.province').mouseover(function(){
			$(this).find('ul').show();
		}).mouseout(function(){
			$(this).find('ul').hide();
		});
		$('.cityall').click(function(){
			var checked = $(this).get(0).checked;
			var citys = $(this).parent().parent().find('.city');
			citys.each(function(){
				$(this).get(0).checked = checked;
			});
			var count = 0;
			if(checked){
				count =  $(this).parent().parent().find('.city:checked').length;
			}
			if(count>0){
				$(this).next().html("(" + count + ")")    ;
			}else{
				$(this).next().html("");
			}
		});
		$('.city').click(function(){
			var checked = $(this).get(0).checked;
			var cityall = $(this).parent().parent().parent().parent().find('.cityall');
			if(checked){
				cityall.get(0).checked = true;
			}
			var count = cityall.parent().parent().find('.city:checked').length;
			if(count>0){
				cityall.next().html("(" + count + ")")    ;
			}else{
				cityall.next().html("");
			}
		});
	})
	
	function addggtype(){
		var gghtml = '<tr>';
		gghtml += '<td class="areasettd">';
    gghtml += '<span class="cityshtml"></span>';
    gghtml += '<input type="hidden" class="citys" name="citys[]" value="" />';
		gghtml += '<button class="layui-btn layui-btn-sm layui-btn-primary" onclick="editArea(this)"><i class="fa fa-edit"></i> 编辑</button>';
		gghtml += '</td>'
		gghtml += '<td><input type="checkbox" name="ispeisong[]" value="1" lay-skin="switch" lay-text="开启|关闭" checked/></td>';
		gghtml += '<td><input type="text" class="layui-input" name="fristweight[]" value="1000" style="width:80px"/></td>';
		gghtml += '<td><input type="text" class="layui-input" name="fristprice[]" value="0" style="width:80px"/></td>';
		gghtml += '<td><input type="text" class="layui-input" name="secondweight[]" value="1000" style="width:80px"/></td>';
		gghtml += '<td><input type="text" class="layui-input" name="secondprice[]" value="0" style="width:80px"/></td>';
		gghtml += '<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>';
		gghtml += '</tr>';
		$('#ggnamediv').append(gghtml);
		layui.form.render('checkbox');
	}
	
	function editArea(btn){
		//current = $(btn).attr('random');
		var areasettd = $(btn).parent();
		clearSelects();
		var old_citys = $(btn).prev().val().split('];');
		console.log(old_citys);
		//$('.cityall').each(function(){
			for(var i in old_citys){
				if(old_citys[i] == '') continue;
				var provincecity = old_citys[i].split('[');
				$('input[province='+provincecity[0]+']').prop('checked',true);
				if(provincecity[1] == '全部地区'){
					$('input[province='+provincecity[0]+']').parent().parent().find('.city').prop('checked',true);
					$('input[province='+provincecity[0]+']').next('.citycount').html('('+$('input[province='+provincecity[0]+']').parent().parent().find('.city').length+')');
				}else{
					var citys = provincecity[1].split(',');
					var citycount = 0;
					for(var j in citys){
						citycount++;
						$('input[province='+provincecity[0]+']').parent().parent().find('.city[city='+citys[j]+']').prop('checked',true);
					}
					$('input[province='+provincecity[0]+']').next('.citycount').html('('+citycount+')');
				}
			}
		//})
		/*
		$('.city').each(function(){
			var parentcheck = false;
			for(var i in old_citys){
				if(old_citys[i]==$(this).attr('city')){
					parentcheck = true;
					$(this).get(0).checked = true;
					break;
				}
			}
			if(parentcheck){
				$(this).parent().parent().parent().parent().find('.cityall').get(0).checked=  true;
			}
		});*/
		
		//$("#modal-areas").modal();
		var areasLayer = layer.open({type:1,skin:'modal-areas',content:$("#modal-areas"),area:['900px','400px'],offset:'50px',shadeClose:true,title:'选择区域',btn:['确定','关闭'],yes:function(){
			
			var citystrs = '';
			$('.cityall:checked').each(function(){
				if($(this).parent().parent().find('.city').length == $(this).parent().parent().find('.city:checked').length){
					citystrs+=$(this).attr('province') + '[全部地区]' + ';';
				}else{
					var citychecked = [];
					$(this).parent().parent().find('.city:checked').each(function(){              
						citychecked.push($(this).attr('city'));
					});
					citystrs+=$(this).attr('province') + '['+citychecked.join(',')+']' + ';';
				}
			})
			//$('.city:checked').each(function(){              
			//	citystrs+= $(this).attr('city') +";";
			//});
			areasettd.find('.cityshtml').html(citystrs);
			areasettd.find('.citys').val(citystrs);
			layer.close(areasLayer);
		}})
	}
	var current = '';
	function clearSelects(){
		$('.city').attr('checked',false).removeAttr('disabled');
		$('.cityall').attr('checked',false).removeAttr('disabled');
		$('.citycount').html('');
	}


	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		if(!field['info[pstimeset]']) field['info[pstimeset]'] = 0;
		var index = layer.load();
		$.post("{:url('save')}",field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status==1){
				setTimeout(function(){
					parent.layer.closeAll();
					parent.tableIns.reload();
				},1000)
			}
		})
	})
  </script>

	<script>
	var lng = $("input[name='info[peisong_lng]']").val();
	var lat = $("input[name='info[peisong_lat]']").val();
	var range = $("input[name='info[peisong_range]']").val();
	var rangetype = '{$info.peisong_rangetype}';
	var rangepath = $("input[name='info[peisong_rangepath]']").val();
	var lnglat = '';//设置的坐标
	if(lng !="" && lat !=""){ 
		lng = parseFloat(lng);
		lat = parseFloat(lat);
		lnglat=[lng,lat];
	}
	{if in_array('hmy_yuyue',getcustom())  && ($bid>0)}
	if(range==0){ range={$ptset['peisong_range']};}
	{else}
	if(range==0){ range=2000;}
	{/if}
	layui.form.on('radio(rangetypeset)',function(data){
		if(data.value == '0'){
			$('#rangetypeset0').show();
			$('#rangetypeset1').hide();
			addcircle();
		}else{
			$('#rangetypeset0').hide();
			$('#rangetypeset1').show();
			addpoly();
		}
	})

	//初始化地图参数
	var map = new AMap.Map("container", {
		resizeEnable: true,//是否监控地图容器尺寸变化，默认值为false
		dragEnable: true,//是否允许拖拽地图
		keyboardEnable: false,//是否允许键盘平移
		doubleClickZoom: false,//是否允许双击放大地图
		scrollWheel:true,//是否允许鼠标滚轮操作地图
		center:lnglat,
		zoom: 13 //地图显示的缩放级别
	});

	var mapcenter = map.getCenter();
	var lng = mapcenter.lng
	var lat = mapcenter.lat
	lnglat = [lng,lat];
	$("input[name='info[peisong_lng]']").val(lng);
	$("input[name='info[peisong_lat]']").val(lat);
	$("input[name='info[peisong_range]']").val(range);

	if(!rangepath){
		var key = 0.02;
		rangepath = [
			[lng - key, lat - key],
			[lng + key, lat - key],
			[lng + key, lat + key],
			[lng - key, lat + key]
		];
	}else{
		rangepathdata = rangepath.split(';');
		rangepath = [];
		for(var i in rangepathdata){
			var path = rangepathdata[i].split(',');
			rangepath.push([path[0],path[1]]);
		}
		console.log(rangepath);
	}
	if(rangetype==0 ){
		addcircle();
	}else{
		addpoly();
	}
	function addcircle(){
		map.clearMap();
		var circlegon = new AMap.Circle({
			center: lnglat,// 圆心位置
			radius: range, //半径
			strokeColor: "#4e73f1", //线颜色
			strokeOpacity: 1, //线透明度
			strokeWeight: 3, //线粗细度
			fillColor: "#4e73f1", //填充颜色
			fillOpacity: 0.35,//填充透明度
		});

		map.add(circlegon)
		map.setFitView([circlegon]);
		
		var circleEditor= new AMap.CircleEditor(map,circlegon);
		circleEditor.open(lnglat);
		
		circleEditor.on('move', function (event) {
			$("input[name='info[peisong_lng]']").val(event.lnglat.lng);
			$("input[name='info[peisong_lat]']").val(event.lnglat.lat);
		});
		circleEditor.on('adjust', function (event) {
			$("input[name='info[peisong_range]']").val(event.radius);
		});
	}
	function addpoly(){
		map.clearMap();
		var polygon = new AMap.Polygon({
			path: rangepath,
			strokeColor: "#FF33FF",
			strokeOpacity: 0.2,
			fillOpacity: 0.4,
			fillColor: '#1791fc',
			zIndex: 50,
			draggable:true
		});
		map.add(polygon)
		map.setFitView([polygon])
		var polyEditor = new AMap.PolyEditor(map, polygon);
		polyEditor.open();
		setpathvalue(polygon);
		polyEditor.on('addnode', function (event) {
			console.log('触发事件：addnode')
			setpathvalue(polygon);
		});
		polyEditor.on('adjust', function (event) {
			console.log('触发事件：adjust');
			setpathvalue(polygon);
		});
		polyEditor.on('removenode', function (event) {
			console.log('触发事件：removenode')
			setpathvalue(polygon);
		});
		polyEditor.on('end', function (event) {
			console.log('触发事件： end')
			setpathvalue(polygon);
		});
		polygon.on('change', function (event) {
			console.log('polygon触发事件： change')
			setpathvalue(polygon);
		});
	}
	function setpathvalue(polygon){
		var pathdata = polygon.getPath();
		var pathArr = [];
		for(var i in pathdata){
			pathArr.push(pathdata[i].lng +','+pathdata[i].lat);
		}
		$("input[name='info[peisong_rangepath]']").val(pathArr.join(';'));
	}

	var dhdata = {$info['formdata']};
	$(function(){
		for(var i=0;i<dhdata.length;i++){
			addelement(dhdata[i].key,dhdata[i].val1,dhdata[i].val2,dhdata[i].val3)
		}
	});
	function toup(obj){
		var onthis=$(obj).parent().parent();  
		var getUp=onthis.prev();
		if (getUp.length<=0)  {  
			layer.msg("到顶了");  
			return;  
		}  
		onthis.after(getUp);  
	}
	function todown(obj){
		var onthis=$(obj).parent().parent();  
		var getdown=onthis.next();
		if (getdown.length<=0){  
			layer.msg("到底了");  
			return;  
		}
		getdown.after(onthis);
	}

	var ekey = 0;
	//添加元素
	function addelement(type,val1,val2,val3){
		if(type=='input'){
			var name = '单行输入';
		}else if(type=='textarea'){
			var name = '多行输入';
		}else if(type=='radio'){
			var name = '单项选择';
		}else if(type=='checkbox'){
			var name = '多项选择';
		}else if(type=='selector'){
			var name = '普通选择';
		}else if(type=='time'){
			var name = '时间选择';
		}else if(type=='date'){
			var name = '日期选择';
		}else if(type=='region'){
			var name = '省市区选择';
		}else if(type=='switch'){
			var name = '开关选择';
		}else if(type=='upload'){
			var name = '上传图片';
		}
		var addhtml = '';
		addhtml += '<tr>'
		addhtml += '<td>'+name+'<input type="hidden" name="datatype['+ekey+']" value="'+type+'"/></td>'
		addhtml += '<td><input class="layui-input" type="text" style="width:120px" name="dataval1['+ekey+']" value="'+val1+'" placeholder="请输入字段名称"></td>'
		addhtml += '<td>'
		if(type=='input'){
			addhtml += '<input class="layui-input" type="text" style="width:200px" name="dataval2['+ekey+']" value="'+val2+'" placeholder="请输入提示信息">'
		}else if(type=='textarea'){
			addhtml += '<input class="layui-input" type="text" style="width:200px" name="dataval2['+ekey+']" value="'+val2+'" placeholder="请输入提示信息">'
		}else if(type=='radio' || type=='checkbox' || type=='selector'){
			if(val2){
				for(var i=0;i<val2.length;i++){
					addhtml += '<div><input class="layui-input" type="text" style="width:180px" name="dataval2['+ekey+'][]" value="'+val2[i]+'" placeholder="请输入选项名称">';
					if(i==0){
						addhtml += '<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="addxuanxiang(this,'+ekey+')"><i class="fa fa-plus"></i></button></div>'
					}else{
						addhtml += '<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="$(this).parent().remove()"><i class="fa fa-minus"></i></button></div>'
					}
				}
			}else{
				addhtml += '<div><input class="layui-input" type="text" style="width:180px" name="dataval2['+ekey+'][]" value="" placeholder="请输入选项名称">';
				addhtml += '<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="addxuanxiang(this,'+ekey+')"><i class="fa fa-plus"></i></button></div>'
			}
		}else if(type == 'time'){

			addhtml += '<div><input class="layui-input" type="text" style="width:200px" name="dataval2['+ekey+'][0]" value="'+(val2[0]?val2[0]:'00:00')+'" placeholder=\'开始时间，格式为"hh:mm"\'>';
			addhtml += '<div><input class="layui-input" type="text" style="width:200px" name="dataval2['+ekey+'][1]" value="'+(val2[1]?val2[1]:'23:59')+'" placeholder=\'结束时间，格式为"hh:mm"\'>';
		}else if(type == 'date'){
			addhtml += '<div><input class="layui-input" type="text" style="width:200px" name="dataval2['+ekey+'][0]" value="'+(val2[0]?val2[0]:'1970-01-01')+'" placeholder=\'开始日期，格式为"YYYY-MM-DD"\'>';
			addhtml += '<div><input class="layui-input" type="text" style="width:200px" name="dataval2['+ekey+'][1]" value="'+(val2[1]?val2[1]:'2080-01-01')+'" placeholder=\'结束日期，格式为"YYYY-MM-DD"\'>';
		}else if(type == 'region'){
			addhtml += '选择省市区';
		}else if(type == 'switch'){
			addhtml += '开启和关闭';
		}else if(type == 'upload'){
			addhtml += '<input class="layui-input" type="text" style="width:200px" name="dataval2['+ekey+']" value="'+val2+'" placeholder="请输入提示信息">'
		}
		addhtml += '</td>'
		//addhtml += '<td><select style="width:60px" name="dataval3['+ekey+']"><option value="1">是</option><option value="0" '+(val3==0?'selected="selected"':'')+'>否</option></select></td>'
		addhtml += '<td><input type="checkbox" name="dataval3['+ekey+']" value="1" lay-skin="switch" lay-text="开启|关闭" '+(val3==1?'checked':'')+'></td>'
		addhtml += '<td>'
		addhtml += '	<button title="删除" type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="$(this).parent().parent().remove()"><i class="fa fa-remove"></i></button>'
		addhtml += '	<button title="上移" type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="toup(this)"><i class="fa fa-arrow-up"></i></button>'
		addhtml += '	<button title="下移" type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="todown(this)"><i class="fa fa-arrow-down"></i></button>'
		addhtml += '</td>'
		addhtml += '</tr>'
		console.log(addhtml)
		$('#datatable').append(addhtml);
		layui.form.render('checkbox');
		ekey++;
	}
	//添加选项
	function addxuanxiang(obj,ekey){
		$(obj).parent().parent().append('<div><input class="layui-input" type="text" style="width:180px" name="dataval2['+ekey+'][]" value="" placeholder="请输入选项名称"><button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="$(this).parent().remove()"><i class="fa fa-minus"></i></button></div>');
	}

	
	function choosezuobiao(){
		var address = '';
		var longitude = $("input[name='info[peisong_lng2]']").val();
		var latitude = $("input[name='info[peisong_lat2]']").val();
		if(!longitude){
			longitude = $("input[name='info[peisong_lng]']").val();
			latitude = $("input[name='info[peisong_lat]']").val();
		}
		var choosezblayer = layer.open({type:2,shadeClose: true,area: ['800px', '560px'],'title': '选择坐标',content: "{:url('DesignerPage/choosezuobiao')}&address="+(address?address:"")+"&jd="+(longitude?longitude:"")+"&wd="+(latitude?latitude:""),btn:['确定','取消'],yes:function(index, layero){
			var longitude = layero.find('iframe').contents().find('#mapjd').val();
			var latitude = layero.find('iframe').contents().find('#mapwd').val();
			$("input[name='info[peisong_lng2]']").val(longitude);
			$("input[name='info[peisong_lat2]']").val(latitude);
			layer.close(choosezblayer);
		}});
	}
	</script>
	{include file="public/copyright"/}
</body>
</html>